package com.scuthnweb.action.reslinkmodule;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.scuthnweb.domain.Account;
import com.scuthnweb.domain.Role;
import com.scuthnweb.domain.Share_link;
import com.scuthnweb.service.ResLinkModule;
import com.scuthnweb.tool.QueryValidateModule;

public class CheckResLinkAction extends ActionSupport{
	
	private Integer sid;
	
	private boolean adminDeletable=false;
	
	private ResLinkModule resLinkModule;
	private QueryValidateModule queryValidateModule;
	
	public String execute(){
		ActionContext ctx = ActionContext.getContext();
		Share_link share_link = this.resLinkModule.checkResLink(sid);
		if(share_link==null)
			return ERROR;
		else{
			Integer uid = (Integer)ctx.getSession().get("user_id");
			if(uid!=null){
				Role role = (Role)this.queryValidateModule.userWholeRole(uid);
				boolean isAdmin = (role.getRole_name().equals("super_admin")||role.getRole_name().equals("admin"))&&role.getAuthority().intValue()==1;
				if( isAdmin )
					this.adminDeletable = true;
			}				
			ctx.getSession().put("linkInfo", share_link);
			Account ac = share_link.getPoster_account();
			ctx.getSession().put("post_user",ac);
			ctx.getSession().put("image_url",this.queryValidateModule.userPicUrl(ac.getId()));
			ctx.getSession().put("adminDeletable", new Boolean(this.adminDeletable));
			return SUCCESS;
		}
	}
	
	public ResLinkModule getResLinkModule() {
		return resLinkModule;
	}

	public void setResLinkModule(ResLinkModule resLinkModule) {
		this.resLinkModule = resLinkModule;
	}

	public Integer getSid() {
		return sid;
	}

	public void setSid(Integer sid) {
		this.sid = sid;
	}

	public QueryValidateModule getQueryValidateModule() {
		return queryValidateModule;
	}

	public void setQueryValidateModule(QueryValidateModule queryValidateModule) {
		this.queryValidateModule = queryValidateModule;
	}
}
